<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            padding-bottom: 800px;
            padding-left: 30px;
        }
        .switch{
            font-size: 36px;
            /* 该样式内部的所有元素大小单位统一使用 em 单位 */
            cursor: pointer;
            user-select: none;
        }
        .text{
            transition:all 150ms ease;
            vertical-align: middle;
        }
        .text.active{
            color: #409eff;
        }
        .pot{
            display: inline-block;
            width: 3em;
            height: 1.5em;
            background-color: #dcdfe6;
            vertical-align: middle;
            margin: 0px 0.4em;
            border-radius:3em;
            transition:all 150ms ease;
            box-shadow: 0 0 0.2em #b1b1b1 inset;
        }
        .pot i{
            display: inline-block;
            width: 1.5em;
            height: 1.5em;
            background-color: white;
            border-radius: 50%;
            transform: scale(0.8);
            transition:all 150ms ease-out;
            box-shadow: 0 0 0.2em #b1b1b1;
        }
        .event{
            display: none;
        }
        .event:checked + .pot{
            background-color: #409eff;
            box-shadow: 0 0 0.2em #2f75bb inset;
        }
        .event:checked + .pot i{
            transform: translate(100%,0) scale(0.8);
            box-shadow: 0 0 0.2em #2f75bb;
        }
    </style>
</head>
<body>
    <div id="app">
        <p>flag1:{{ flag1 }}</p>
        <my-switch v-model="flag1" :text="['左边标签','右边标签']"></my-switch>
        <p>flag2:{{ flag2 }}</p>
        <my-switch v-model="flag2" style="font-size:12px"></my-switch>
    </div>
    <script type="text/x-template" id="mySwitch">
        <label class="switch" style="font-size: 24px;">
            <span class="text" :class="{ active:!value }">{{ text[0] }}</span>
            <input class="event" type="checkbox" v-model="value">
            <span class="pot">
                <i></i>
            </span>
            <span class="text" :class="{ active:value }">{{ text[1] }}</span>
        </label>
    </script>
    <script type="module">
        // 加载 Vue3 的ESM 模块文件
        import { createApp } from "../assets/vue3/vue.esm-browser.js"
        const MySwitch = {
            template:"#mySwitch",
            props: {
                modelValue: {
                    type:Boolean
                },
                text:{
                    type:Array,
                    default(){
                        return ["",""]
                    }
                }
            },
            emits:["update:modelValue"],
            computed: {
                value:{
                    get(){
                        return this.modelValue
                    },
                    set(nv){
                        this.$emit("update:modelValue",nv)
                    }
                }
            },
        }
        createApp({
            components: {
                MySwitch,
            },
            data(){
                return {
                    flag1:false,
                    flag2:true,
                }
            }
        }).mount("#app")
    </script>
</body>
</html>